package com.zhang.myShardingJob.job;

import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
import org.springframework.stereotype.Service;

import java.util.Date;

@Slf4j
@Service
public class MyShardingJob implements SimpleJob {
    @Override
    public void execute(ShardingContext shardingContext) {
        // sharding-total-count=3，所以任务被分为三个分片
        switch (shardingContext.getShardingItem()) {
            case 0:
                //log.info("执行器2分片1：执行任务 " + new Date());
                System.out.println("执行器2执行：分片1：执行任务 " + new Date());
                break;
            case 1:
                //log.info("执行器2分片2：执行任务 " + new Date());
                System.out.println("执行器2执行：分片2：执行任务 " + new Date());
                break;
            case 2:
                //log.info("执行器2分片3：执行任务 " + new Date());
                System.out.println("执行器2执行：分片3：执行任务 " + new Date());
                break;
        }
    }
}
